package
{
	import flare.display.RectSprite;
	import flare.display.TextSprite;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.*;
	
	public class InputText extends Sprite
	{
		private var fieldName:String;
		
		private var textInput:TextField;
		
		private var button:Sprite;
		
		public function InputText(fieldName:String)
		{
			this.fieldName = fieldName;
			
			// add input text field
			textInput = new TextField();
			textInput.type = TextFieldType.INPUT;
			textInput.x = 0;
			textInput.y = 20;
			textInput.width = 360;
			textInput.height = 30;
			textInput.border = true;
			this.addChild(textInput);
			
			// add button
			button = new Sprite();
			button.x = 380;
			button.y = 20;
			button.graphics.lineStyle(1, 0x000000);
			button.graphics.beginFill(0x33cccc);
			button.graphics.drawRoundRect(0, 0, 100, 30, 5, 5);
			button.graphics.endFill();
			button.visible = true;
			this.addChild(button);
			button.addEventListener(MouseEvent.CLICK, onClick);
			
			// add button text on top of button
			var buttonText:TextSprite = new TextSprite(fieldName);
			buttonText.x = 3;
			buttonText.y = 4;
			buttonText.color = 0x000000;
			buttonText.size = 15;
			buttonText.font = "Arial";
			button.addChild(buttonText);
		}
		
		public function onClick(e:Event):void {
			this.dispatchEvent(new Event(this.fieldName, true));
		}
		
		public function getTextContent():String {
			return textInput.text;
		}
	}
}